<?php
require_once("../connection.php");

$user  = $_POST['user'];
$val  = mysql_real_escape_string($_POST['val']);
$val = htmlentities($val);  // for removing all tags except break

$postas = $_POST['postas'];
$type = $_POST['type'];

date_default_timezone_set('Asia/Calcutta');
$time = time();

$arr = explode("_",$type);
$postid = $arr[3];
$type1 = "comment_post_".$postid; 

$res = mysql_query("INSERT INTO site_comments (`type`,`user`,`postas`,`text`,`timestamp`) VALUES('$type1','$user','$postas','$val','$time')");
if(!$res) echo mysql_error();

$id = mysql_insert_id();
echo "id_".$id;


//updating the site_posts table for the freshness parameter
$res1 = mysql_query("UPDATE site_posts SET `freshness`='$time' WHERE `id`='$postid'");
if(!$res1) echo mysql_error();
?>